import { defineStore } from "pinia";
import { store } from "@/store";
import { getList, update, add, deleted ,get } from "@/api/cv/enterprise";
import { ListResult, Result } from "@/api/cv/enterprise";

export const enterpriseCVStore = defineStore({
  id: "pure-enterpriseCV",
  actions: {
    //获取用户列表
    async getList(req: object) {
      return new Promise<ListResult>((resolve, reject) => {
        getList(req)
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    async update(req: object) {
      return new Promise<Result>((resolve, reject) => {
        update(req)
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    async add(req: object) {
      return new Promise<Result>((resolve, reject) => {
        add(req)
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    async delete(req: object) {
      return new Promise<Result>((resolve, reject) => {
        deleted(req)
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    async get(req: object) {
      return new Promise<Result>((resolve, reject) => {
        get(req)
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    }
  }
});

export function enterpriseCVStoreHook() {
  return enterpriseCVStore(store);
}
